define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'withdrawal/index' + location.search,
                    // add_url: 'withdrawal/add',
                    edit_url: 'withdrawal/edit',
                    // del_url: 'withdrawal/del',
                    // multi_url: 'withdrawal/multi',
                    import_url: 'withdrawal/import',
                    table: 'withdrawal',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'order_num', title: __('Order_num'), operate: 'LIKE'},
                        {field: 'moneytype_name', title: __('Moneytype')},
                        {
                            field: 'type',
                            title: __('Type'),
                            searchList: {
                                "person": __('个人账户'),
                                "company": __('对公账户'),
                                "wechat": __('微信'),
                                "alipay": __('支付宝')
                            },
                            formatter: Table.api.formatter.normal
                        },
                        // {field: 'user_id', title: __('User_id')},
                        // {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {field: 'money', title: __('Money'), operate: 'BETWEEN'},
                        {field: 'fee', title: __('Fee'), operate: 'BETWEEN'},
                        // {field: 'hasmoney', title: __('Hasmoney'), operate:'BETWEEN'},
                        {
                            field: 'account_info',
                            title: __('Account_info'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {
                            field: 'status',
                            title: __('Status'),
                            searchList: {"-1": __('拒绝'), "0": __('待审核'), "1": __('同意')},
                            formatter: Table.api.formatter.status
                        },
                        {
                            field: 'createtime',
                            title: __('Createtime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'message',
                            title: __('Message'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        // {field: 'replyms', title: __('Replyms'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {
                            field: 'handtime',
                            title: __('Handtime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },

                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            // buttons: [
                            //     {
                            //         name: 'edit', //唯一标识、权限标识
                            //         text: '编辑', //按钮显示的文字，支持function
                            //         title: '编辑', //按钮显示的文字，支持function
                            //         classname: 'btn btn-info btn-xs btn-dialog', //按钮的class，支持btn-dialog/btn-ajax/btn-addtabs
                            //         url: 'Withdrawal/handleOrder/id/{id}', //按钮的链接，支持使用{字段名}来占位替换，支持function
                            //
                            //         visible: function (row) {
                            //             if (row.status != 0) {
                            //                 return false;
                            //             } else {
                            //                 return true;
                            //             }
                            //         }, //判断按钮是否可见，支持function
                            //
                            //         extend: '', //扩展的扩展属性，FastAdmin1.4.0+支持function
                            //     }
                            // ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
